function main() {
    // 线索移交
    const self = this;
    debugger

    const formEle = self.$$("form_part_fvxfbx").$$getRenderElement();

    // 督办状态 status 待发送、已发送、办理中、已撤回、已反馈、已办结
    self.$$("number_input_hib6mp").cValue = 0;

    formEle.onSave().then(res => {
        console.log(res);
        const taskId = res.result['ds_tbl:t_91f06a36e9df4bf0981df72a4a2417f2-9e5a'].id; // 督办任务id
        const objectId = res.result['ds_tbl:t_91f06a36e9df4bf0981df72a4a2417f2-9e5a'].tree_single_select_93hk4h.replace('unit', '');
        const objectName = self.$$("tree_single_select_93hk4h").selectedData[0].name;

        let username = api.USER_INFO().name;
        let handleRecord = {
            replyId: taskId,
            recordType: 2,
            recordTitle: "督办登记",
            recordContent: `督办人员${username}登记了督办事项。`,
            relationReplyId: ""
        }

        let taskData = {
            taskId: taskId,
            objectId: objectId,
            objectName: objectName
        }

        insertTaskObject(taskData).then(r => {
            // 新增督办记录
            insertHandleRecord(handleRecord).then(r => {
                console.log("res", "执行结果,修改成功！");
                notifyParentAndClose(self)
            });
        });
    });
}

/**
 * 新增督办对象
 * @param clueData
 */
function insertTaskObject(clueData) {
    return new Promise((resolve, reject) => {
        api.EXEC_FORMULA("API_CALL('ds_api:deef77e2-7e67-4bae-acbd-cbd468cfca82-9e5a', 'userId',USER_ID(), 'result.uid')").then(res => {

            let userId = res.result;
            api.DATA_SOURCE_EXECUTE("ds_mod:bcc76ab7-aa47-483a-bb7a-bd074476e003", "ddcat", [], [], "").then(res => {
                let unit_id = res.result.uid
                const insertTaskObjects = [
                    ['task_id', clueData.taskId],
                    ['opt_human_id', `'${userId}'`],
                    ['lead_unit_id', `'${unit_id}'`],
                    ['object_id', `'${clueData.objectId}'`],
                    ['object_name', `'${clueData.objectName}'`],
                    ['object_type', '1'],
                    ['receive_status', '0'],
                    ['finish_status', '0'],
                    ['delete_flag', `'0'`],
                    ['create_time', 'NOW()'],
                    ['create_human_id', `'${userId}'`],
                ];

                const formattedFields = insertTaskObjects.map(([key, value]) => {
                    return `'${key}',${value}`;
                });

                const law_std_sup_task_object = "ds_tbl:t_c232a327f2a44a8dbfa0c5a1c74a2026-9e5a";
                const insertSql = `INSERT('${law_std_sup_task_object}', [${formattedFields.join(',')}])`;
                console.log(insertSql);


                api.EXEC_FORMULA(insertSql).then(res => {
                    console.log(res);
                    resolve(res);
                })
            })
        })
    });
}

/**
 * 处理经过
 * @param recordData
 * @returns {Promise<unknown>}
 */
function insertHandleRecord(recordData) {
    return new Promise((resolve, reject) => {
        api.EXEC_FORMULA("API_CALL('ds_api:deef77e2-7e67-4bae-acbd-cbd468cfca82-9e5a', 'userId',USER_ID(), 'result.uid')").then(res => {

            let userId = res.result;
            const insertHandleRecords = [
                ['record_uid', 'UUID()'],
                ['relation_id', `'${recordData.replyId}'`],
                ['record_type', `'${recordData.recordType}'`],
                ['record_title', `'${recordData.recordTitle}'`],
                ['record_content', `'${recordData.recordContent}'`],
                ['create_time', 'NOW()'],
                ['create_human_id', `'${userId}'`],
                ['relation_reply_id', `'${recordData.relationReplyId}'`]
            ];

            const formattedFields = insertHandleRecords.map(([key, value]) => {
                return `'${key}',${value}`;
            });

            const law_std_sup_handle_record = "ds_tbl:t_0ff47ea0e3a74ffdbc274409e7103e7e-9e5a";
            const insertSql = `INSERT('${law_std_sup_handle_record}', [${formattedFields.join(',')}])`;
            console.log(insertSql);


            api.EXEC_FORMULA(insertSql).then(res => {
                console.log(res);
                resolve(res);
            })
        })
    });


}


function notifyParentAndClose(self) {

    let pageListEle = window.cluePageList;
    // 获取列表渲染页实例
    const listRenderView = pageListEle.$$getRenderElement();
    // 获取当前显示的组件，表格或者卡片
    const currentListEle = listRenderView.$$getListElement();
    // 调用刷新方法
    currentListEle.$$refreshData();

    if (window.parent) {
        window.parent.postMessage(
            JSON.stringify({event: "close-dialog", param: {XXX: "test"}}),
            "*"
        );
    }
}
